using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;

/// <summary>
/// Summary description for SeminarDAO
/// </summary>
public class SeminarDAO:DataProvider
{
    public ArrayList LayMang_Seminar()
    {
        connect();
        ArrayList arr = new ArrayList();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Select_Seminar", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                SeminarDTO sdto = new SeminarDTO();
                sdto.MaSeminar = dr.GetInt32(0);
                sdto.MaNguoiTrinhBay = dr.GetString(1);
                sdto.VanDeTB = dr.GetString(2);
                sdto.TomTatNoiDung = dr.GetString(3);
                sdto.NgaySeminar= dr.GetDateTime(4);                
                sdto.MaHuongNC = dr.GetInt32(5);
                sdto.TaiLieuDinhKem = dr.GetString(6);
                sdto.NhanXet = dr.GetString(7);                
                arr.Add(sdto);
            }
        }
        catch (Exception es)
        {
            throw es;
        }
        return arr;

    }
    public void insert(SeminarDTO sdto)
    {
        connect();

        try
        {
            SqlCommand cmd = new SqlCommand("sp_Insert_Seminar", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@manguoitb", SqlDbType.NVarChar);
            cmd.Parameters["@manguoitb"].Value = sdto.MaHuongNC.ToString();
            cmd.Parameters["@manguoitb"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@vandetb", SqlDbType.Text);
            cmd.Parameters["@vandetb"].Value = sdto.VanDeTB.ToString();
            cmd.Parameters["@vandetb"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@tomtat",SqlDbType.Text);
            cmd.Parameters["@tomtat"].Value = sdto.TomTatNoiDung.ToString();
            cmd.Parameters["@tomtat"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@ngay", SqlDbType.SmallDateTime);
            cmd.Parameters["@ngay"].Value =sdto.NgaySeminar.ToString();
            cmd.Parameters["@ngay"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@mahnc", SqlDbType.Int);
            cmd.Parameters["@mahnc"].Value = sdto.MaHuongNC;
            cmd.Parameters["@mahnc"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@tailieu", SqlDbType.NVarChar);
            cmd.Parameters["@tailieu"].Value = sdto.TaiLieuDinhKem.ToString();
            cmd.Parameters["@tailieu"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@nhanxet",SqlDbType.Text);
            cmd.Parameters["@nhanxet"].Value = sdto.NhanXet.ToString();
            cmd.Parameters["@nhanxet"].Direction = ParameterDirection.Input;
            cmd.ExecuteNonQuery();
        }
        catch (Exception es)
        {
            throw es;
        }
    }
    public void delete(int maseminar)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Delete_Seminar", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@maseminar", SqlDbType.Int);
            cmd.Parameters["@maseminar"].Value = maseminar;
            cmd.Parameters["@maseminar"].Direction = ParameterDirection.Input;
            cmd.ExecuteNonQuery();

        }
        catch (Exception es)
        {
            throw es;
        }
    }
    public void update(SeminarDTO sdto)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Update_Seminar", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@maseminar", SqlDbType.Int);
            cmd.Parameters["@maseminar"].Value = sdto.MaSeminar;
            cmd.Parameters["@maseminar"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@manguoitb", SqlDbType.Int);
            cmd.Parameters["@manguoitb"].Value = sdto.MaNguoiTrinhBay;
            cmd.Parameters["@manguoitb"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@vandetb", SqlDbType.Text);
            cmd.Parameters["@vandetb"].Value = sdto.VanDeTB.ToString();
            cmd.Parameters["@vandetb"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@tomtat", SqlDbType.Text);
            cmd.Parameters["@tomtat"].Value = sdto.TomTatNoiDung.ToString();
            cmd.Parameters["@tomtat"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@ngay", SqlDbType.SmallDateTime);
            cmd.Parameters["@ngay"].Value = sdto.NgaySeminar.ToString();
            cmd.Parameters["@ngay"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@mahuongnc", SqlDbType.Int);
            cmd.Parameters["@mahuongnc"].Value = sdto.MaHuongNC;
            cmd.Parameters["@mahuongnc"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@tailieu", SqlDbType.NVarChar);
            cmd.Parameters["@tailieu"].Value = sdto.TaiLieuDinhKem.ToString();
            cmd.Parameters["@tailieu"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@nhanxet",SqlDbType.Text);
            cmd.Parameters["@nhanxet"].Value = sdto.NhanXet.ToString();
            cmd.Parameters["@nhanxet"].Direction = ParameterDirection.Input;

            cmd.ExecuteNonQuery();
     
        }
        catch (System.Exception ex)
        {
            throw ex;
        }
    }
	public SeminarDAO()
	{
		//
		// TODO: Add constructor logic here
		//
	}
}
